/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.scm.hibernate.entities;

import com.scm.hibernate.utilities.HibernateUtil;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import org.hibernate.Query;
import org.hibernate.Session;

/**
 *
 * @author Sony
 */

@Table(name = "faculties")
@Entity
public class Faculty extends AbstractEntity
{
    @Id
    @GeneratedValue
    @Column(name = "id")
    protected  Long id;
    
    @Column(name = "fname")
    protected  String fname ;
    
    @Column(name = "lname")
    protected  String lname;
    
    @Column(name = "mname")
    protected  String mname;
    
    @Column(name = "gender")
    protected  String gender;
    
    @Column(name = "email")
    protected  String email;
    
    @Column(name = "password")
    protected  String password;
    
    @Column(name = "address")
    protected  String address;
    
    @Column(name = "city")
    protected  String city;
    
    @Column(name = "f_state")
    protected  String f_state;
    
    @Column(name = "contact")
    protected  String contact;
    
    @Column(name = "dateofbirth")
    protected  String dateofbirth;
    
    @Column(name = "dateofjoin")
    protected  String dateofjoin;
    
    @Column(name = "qualification")
    protected  String qualification;
    
    @Column(name = "designation")
    protected  String designation; 
    
    @Column(name = "addedby")
    protected  Long addedby;

    public String getFname() {
        return fname;
    }

    public void setFname(String fname) {
        this.fname = fname;
    }

    public String getLname() {
        return lname;
    }

    public void setLname(String lname) {
        this.lname = lname;
    }

    public String getMname() {
        return mname;
    }

    public void setMname(String mname) {
        this.mname = mname;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getF_state() {
        return f_state;
    }

    public void setF_state(String f_state) {
        this.f_state = f_state;
    }

    public String getContact() {
        return contact;
    }

    public void setContact(String contact) {
        this.contact = contact;
    }

    public String getDateofbirth() {
        return dateofbirth;
    }

    public void setDateofbirth(String dateofbirth) {
        this.dateofbirth = dateofbirth;
    }

    public String getDateofjoin() {
        return dateofjoin;
    }

    public void setDateofjoin(String dateofjoin) {
        this.dateofjoin = dateofjoin;
    }

    public String getQualification() {
        return qualification;
    }

    public void setQualification(String qualification) {
        this.qualification = qualification;
    }

    public String getDesignation() {
        return designation;
    }

    public void setDesignation(String designation) {
        this.designation = designation;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getAddedby() {
        return addedby;
    }

    public void setAddedby(Long addedby) {
        this.addedby = addedby;
    }
    
     public Faculty verify()
   {
       Faculty f=null;
       try 
       {
           Session ss=HibernateUtil.getSessionFactory().openSession();
           Query q=ss.createQuery("from Faculty where email='"+this.email+"'");
           
           List<Faculty> li=q.list();
           
           if(li.size()==1)
           {
               f=li.get(0);
           }
                      
       }
       catch (Exception e) 
       {
           e.printStackTrace();
       }
       
       return f;
   }
      public static List<Faculty> getallfaculties() {
        List<Faculty> li = null;
        try {
            Session s = HibernateUtil.getSessionFactory().openSession();

            Query q = s.createQuery("from Faculty");

            li = q.list();
            System.out.println("Get All Fac");

        } catch (Exception e) {
               e.printStackTrace();
        }
        return li;
    }

    @Override
    public String toString() {
        return this.fname + " : " + this.designation;
    }

      
    
}
